#include"Window.h"
Window::Window()
{}
Window::Window(char *title, int w, int h)
{
	Title = (char *) malloc(STR);
	strcpy(Title, title);
	Width = w;
	Height = h;
}
Window::~Window()
{
	free(Title);
}
/****************************************************************************
 *  Name       : createWindow
 *  Parameters : Title of the Window
 *               Width of the Window
 *               Height of the Window
 *  Returns    : Nothing
 *  Purpose    : To reinitialize an existing Window object.
 ****************************************************************************/
void Window::createWindow(char *title, int w, int h)
{
	Title = (char *) malloc(STR);
	strcpy(Title, title);
	Width = w;
	Height = h;
}
/****************************************************************************
 *  Name       : getWindowRect
 *  Parameters : None
 *  Returns    : Rectangle containing the Window coordinates
 *  Purpose    : To get the coordinates of the Window.
 ****************************************************************************/
inline Rectangle Window::getWindowRect()
{
	return WindowRect;
}
/****************************************************************************
 *  Name       : getWidth
 *  Parameters : None
 *  Returns    : Width of the Window
 *  Purpose    : To get the Width of the Window.
 ****************************************************************************/
inline int Window::getWidth()
{
	return (WindowRect.right - WindowRect.left);
}
/****************************************************************************
 *  Name       : getHeight
 *  Parameters : None
 *  Returns    : Height of the Window
 *  Purpose    : To get the Height of the Window.
 ****************************************************************************/
inline int Window::getHeight()
{
	return (WindowRect.bottom - WindowRect.top);
}
/****************************************************************************
 *  Name       : setXY
 *  Parameters : X position
 *               Y position
 *  Returns    : Nothing
 *  Purpose    : To set the coordinates of the Window Rectangle and to
 *               calculate the X position where the Title has to be displayed.
 ****************************************************************************/
void Window::setXY(int x, int y)
{
	WindowRect.left   = x;
	WindowRect.top    = y;
	WindowRect.right  = x + Width + 2;
	WindowRect.bottom = y + Height + 1;
	TitlePos = (x + WindowRect.right  - strlen(Title)) >> 1;
}
/****************************************************************************
 *  Name       : showWindow
 *  Parameters : None
 *  Returns    : Nothing
 *  Purpose    : Draws the Window on the screen.
 ****************************************************************************/
void Window::showWindow()
{
	fillBox(WindowRect, D_TXT);
	drawDoubleRect(WindowRect, D_TXT);
	putStr(TitlePos, WindowRect.top, Title, D_HOT, D_TXT);
}
// Class Window ends here